{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>新增商品</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">商品名称：</label>
                            <div class="layui-input-block">
                                <input type="text" name="bg_name" lay-verify="required" placeholder="商品名称" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">类型：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="bg_type" value="1" class="layui-input" title="花样青青" checked/>
                                <input type="radio" name="bg_type" value="2" class="layui-input" title="脖脸皮"/>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">产品码：</label>
                            <div class="layui-input-block">
                                <input type="text" name="bg_product_code" lay-verify="required" placeholder="产品码" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">缩略图：</label>
                            <input type="hidden" name="bg_thumb" id="lay-img" lay-verify="image">
                            <div class="layui-input-block">
                                <div id="lay-upload">上传图片</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="lay-list">
                                    </div>
                                </blockquote>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">商品图集：</label>
                            <div class="layui-input-block">
                                <input type="hidden" name="bg_images" id="photo" lay-verify="image">
                                <div id="uploader" class="container-s">
                                    <div class="queueList">
                                        <div class="placeholder">
                                            <div id="filePicker"></div>
                                            <p>或将照片拖到这里</p>
                                        </div>
                                    </div>
                                    <div class="statusBar" style="display:none;">
                                        <div class="layui-progress layui-progress-big active-s" lay-showpercent="true">
                                            <div class="layui-progress-bar layui-bg-blue" lay-percent="0%">
                                            </div>
                                            <span></span>
                                        </div>
                                        <div class="info"></div>
                                        <div class="btns">
                                            <div id="goPicker" class="filePicker2"></div>
                                            <div class="uploadBtn">开始上传</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">一级分类：</label>
                            <div class="layui-input-block">
                                <select name="bg_first_cate" lay-search="" id="irst_cate"  lay-filter="first_cate">
                                    <option value="">---- 请选择一级分类 ----</option>
                                    {foreach name="cate" item="vo"}
                                    <option value="{$vo.bgc_id}" >{$vo.bgc_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">二级分类：</label>
                            <div class="layui-input-block" id="bg_second_cate">
                                <select name="bg_second_cate">
                                    <option value="">---- 请选择二级分类 ----</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">商品状态：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="bg_status" value="1" class="layui-input" title="上架" checked/>
                                <input type="radio" name="bg_status" value="2" class="layui-input" title="下架"/>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">是否推荐：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="bg_is_commend" value="2" class="layui-input" title="推荐" checked/>
                                <input type="radio" name="bg_is_commend" value="1" class="layui-input" title="不推荐"/>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">会员价格：</label>
                            <div class="layui-input-block">
                                <input type="text" name="bg_price" lay-verify="required" placeholder="会员价格" class="layui-input" oninput="value=value.replace(/[^\d.]/g,'')">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">原价：</label>
                            <div class="layui-input-block">
                                <input type="text" name="bg_old_price" lay-verify="required" placeholder="原价" class="layui-input" oninput="value=value.replace(/[^\d.]/g,'')">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">规格：</label>
                            <div class="layui-input-block">
                                <input type="text" name="bg_spec" lay-verify="required" placeholder="例如：10ml" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">库存：</label>
                            <div class="layui-input-block">
                                <input type="text" name="bg_stock" lay-verify="required" placeholder="库存" class="layui-input" oninput="value=value.replace(/[^\d]+/g,'')">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">排序：</label>
                            <div class="layui-input-block">
                                <input type="text" name="bg_sort" placeholder="排序，值越大越靠前" class="layui-input" oninput="value=value.replace(/[^\d]+/g,'')">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">商品详情：</label>
                            <div class="layui-input-block" id="LAY_editor" lay-verify="editor">
                                <p></p>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
<!--                                <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

{include file="public/footer" /}
<script>
    wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""});
    var n = wk.uploads({num:6,type:'png,jpg,jpeg',url:"{:url('admin/upload/upload')}"});
    function imgDel(e,obj){
        wk.uploads_del(e,obj,n); // 删除
    }
    var editor = wk.wang({elem:'#LAY_editor'});
    layui.use(['form','upload','layedit','laydate'], function() {
        var form = layui.form;
        form.verify({
            editor:function(value,item){
                if(editor.txt.html() == '<p><br></p>'){
                    return '请填写内容';
                }
            }
        });

        form.on('submit(component-form-element)', function (data) {
            data.field.bg_content = editor.txt.html();
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('goodsAdd')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            wk.layer_close();
                        });
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            });
        });

        form.on('select(first_cate)', function (data){
            $.ajax({
                url:"{:url('admin/Base/boGoodsCate')}",
                dataType:"json",
                data:'id=' + data.value,
                type:'post',
                success:function (res){
                    if(res.code == 200){
                        res_data = res.msg;
                        $('#bg_second_cate').children().remove();
                        bg_second_cate = xmSelect.render({
                            tips: '---- 请选择二级分类 ----',
                            filterable: true, // 开启搜索模式
                            toolbar: {show: true},
                            prop: {
                                name: 'bgc_name',
                                value: 'bgc_id',
                            },
                            el: '#bg_second_cate',
                            language: 'zn',
                            data:res_data
                        });
                    }else{
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
    });
</script>

</body>
</html>